What is Deque in Data Structure? | Data Structure Tutorial
In this article, you will learn about:
- What is Deque?
- Different Types of Deque
- Different Operations on a Deque
- Application of Deque
What is a deque?
Deque (Double Ended Queue) is a type of queue in which insertion and deletion of items can be done from both the ends such as FRONT and REAR. It does not follow the rule of First In First Out (FIFO).
Different types of Deque
- Input Restricted Deque: In this type of Deque, the input can be done only from one end but the deletion of an element can be done from both ends.
- Output Restricted Deque: In this type of Deque, the output can be done only from one end either from FRONT and REAR but the insertion can be done from the ends.
Operations on a Deque:
In a normal array implementation, if the array is full, no more elements can be added. In each of the operations below, if the array is full, it will display the “Overflow message”.
Before executing the following operations, these steps need to be followed:
- Take a deque of ‘n’ size.
- Set the value of the two pointers at the first position and set
FRONT = -1 and REAR =0
Insert at the FRONT
- Examine the position of FRONT.
- If the value of the FRONT < 1, reinitialize FRONT = N-1(i.e the last index)
- Now, decrease the value of FRONT by 1.
- Insert the new key 5 into array[FRONT]
Insert at the REAR
- Examine if the array is full.
- If the deque is full, it will initialize the value of the REAR = 0
- Now, increase the value of REAR by 1.
- Insert the new key 5 into array[REAR]
Delete from the FRONT End
- Examine if the deque is empty.
- If there is no item in the deque, deletion cannot take place. This condition is known as the underflow condition.
- If the deque has only one element, then set FRONT = -1 and REAR = -1.
- If FRONT is at the end of the deque, set go to the front FRONT = 0.
- Eles, set FRONT = FRONT +1
Delete from the REAR End
- Examine if the deque is empty
- If the deque is empty, then deletion can not be performed. This condition is also known as the underflow condition.
- If the deque has only one element, then set FRONT = -1 and REAR = -1.
- If the value of the REAR is FRONT, then set the REAR = n - 1.
- Else, set REAR = REAR - 1.
Check empty
If the FRONT = -1, then it means the deque is empty
Check Full
If the value of the FRONT = 0 AND REAR = n - 1, then it means the deque is full.
Applications of Deque
- To store history in browsers.
- For implementing stacks and queues
- In undo operations on software


